﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    public class 基类和派生类的构造函数
    {
        public void F1()
        {
            child c1 = new child();
            child c2 = new child(2, 3);
            child c3 = new child(2);
            //结果表明调用子类的构造函数是先调用基类的
        }
    }

    class super
    {
        public super()
        {
            Console.WriteLine("super constructor no param");
        }
        public super(int a)
        {
            Console.WriteLine("super constructor with param");
        }
    }
    class child : super
    {
        //不写base()也会先调用基类的无参构造函数
        //public child()
        //{
        //    Console.WriteLine("wfwafwaefwafewfwaefejwajeiof");
        //}

        //base表示调用的是基类的构造函数 this表示的是本类的
        public child(int a) //调用基类的有参构造函数
            : base(a)
        {
            Console.WriteLine("子类的单参数构造函数");
        }

        public child()
            : this(2, 3)
        {
            Console.WriteLine("子类无参构造方法");
        }

        public child(int b, int c)
        {
            Console.WriteLine("子类有参构造函数");
        }

    }
}
